package com.ermao.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 代码级别自动填充，留下数据库记录创建时间和修改时间
 * @author Ermao
 * Date: 2021/8/31 20:30
 */
@Component
public class AutoFillHandler implements MetaObjectHandler {
	// TODO 解决自动填充的bug 主要是使用 update 的原因
	@Override
	public void insertFill(MetaObject metaObject) {
		this.strictInsertFill(metaObject, "createTime", Date::new, Date.class);
		this.strictInsertFill(metaObject, "updateTime", Date::new, Date.class);
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		this.strictInsertFill(metaObject, "updateTime", Date::new, Date.class);
	}
}
